import logo from '/static/logo.png'
const app = {
	state: {
		mode: 'pc',
		appMeunShow:false,
		sysConfig:{
			logo:logo, //当不为空时，更换logo,否则用默认的
			siteName: '源头云', //当不为空时，更换网站名称,否则用默认的
		}
	},
	mutations: {
		setMode(state, mode) {
			state.mode = mode;
		},
		setAppMeunShow(state, appMeunShow) {
			state.appMeunShow = appMeunShow;
		},
		SET_sysConfig(state, sysConfig){
			state.sysConfig = {
				...state.sysConfig,
				logo:sysConfig.logoUrl?sysConfig.logoUrl:logo,
				siteName:sysConfig.siteName?sysConfig.siteName:state.sysConfig.siteName
			};
		},
	},
	actions: {
		// 设置当前页面模式
		setModeFn({commit,state},_this) {
			let mediaQueryOb = uni.createMediaQueryObserver(_this)
			mediaQueryOb.observe({
				minWidth: 375, //页面最小宽度 375px
				maxWidth: 1000 //页面宽度最大 500px
			}, matches => {
				let mode = matches == true ? 'app' : 'pc';
				commit('setMode',mode)
			})
		},
		// 设置app菜单展示和隐藏
		setAppMeunShowFn({commit,state},onoff) {
			commit('setAppMeunShow',onoff)
		},
		// 获取网站基本信息
		getWebsiteInfo({
			commit,
			state
		}) {
			// return new Promise((resolve, reject) => {
			// 	uni.$http.get('/saasWapAuth/websiteInfo', {}).then(res => {
			// 		if (res.code == 200) {
			// 			commit('SET_sysConfig', res.data)
			// 		}
			// 		resolve(res.data)
			// 	}).catch(error => {
			// 		reject(error)
			// 	})
			// })
		},
		// lazy loading openid
		getUserOpenId: async function({
			commit,
			state
		}) {
			return await new Promise((resolve, reject) => {
				if (state.openid) {
					resolve(state.openid)
				} else {
					
				}
			})
		},
	}
}

export default app
